package gui;

import javax.swing.*;
import java.awt.*;

/**
 * @author brianegge
 * @license http://www.freebsd.org/copyright/license.html  BSD License (4 Clause)
 */
public class Navigator {
    JPanel panel = new JPanel();
    JLabel label = new JLabel();
    SameComboBox comboBox = new SameComboBox();
    JButton next = new JButton();
    JButton previous = new JButton();

    void setup(JPanel panel, boolean leftpos) {
        this.panel.setLayout(new BoxLayout(this.panel, BoxLayout.X_AXIS));

        if (leftpos) {
            this.panel.add(Box.createHorizontalGlue());
            addToNagivator(this.panel, label, comboBox, previous, next);
        } else {
            addToNagivator(this.panel, label, comboBox, previous, next);
            this.panel.add(Box.createHorizontalGlue());
        }
        panel.add(this.panel, BorderLayout.PAGE_END);
    }

    private static void addToNagivator(JPanel navi, JLabel label, JComboBox comboBox, JButton previous, JButton next) {
        addComponentToNavigator(navi, label);
        addComponentToNavigator(navi, comboBox);
        addComponentToNavigator(navi, previous);
        addComponentToNavigator(navi, next);
    }

    private static void addComponentToNavigator(final JPanel navi, final Component component) {
        navi.add(component);
        navi.add(Box.createRigidArea(new Dimension(10, -1)));
    }

}
